package com.xiaotu.util;

import java.io.Serializable;
/**
 * 统一整个项目中AJAX请求(返回的结果)(可以用于分布式架构哥哥模块间调用时返回统一类型)
 *
 * */
public class ResultEntity<T> implements Serializable {
    public static final String success = "SUCCESS";
    public static final String failed = "FAILED";
    //用来封装当前请求处理结果是成功还是失败
    private String result;
    //请求处理失败时,返回的错误消息
    private String msg;
    //需要返回的数据
    private T data;
    public ResultEntity() {
    }
    public ResultEntity(String result, String msg, T data) {
        this.result = result;
        this.msg = msg;
        this.data = data;
    }
    public String getResult() {
        return result;
    }
    public void setResult(String result) {
        this.result = result;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
    /*请求处理成功不需要返回数据的工具方法*/
    public static <T> ResultEntity<T> success(){
        return new ResultEntity<T>(success,null,null);
    }
    /*请求处理成功 需要返回数据的工具方法*/
    public static <T> ResultEntity<T> success(T data){
        return new ResultEntity<T>(success, null, data);
    }
    /*请求失败 返回的工具方法*/
    public static <T> ResultEntity<T> fail(String msg){
        return new ResultEntity<>(failed, msg, null);
    }
}
